package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.contract.business.InsertCustomInfoContract;
import www.openteam.com.contract.business.InsertProductInfoContract;
import www.openteam.com.model.business.InsertProductInfoModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.BuildProductInfoFragment;

/**
 * Created by kylin on 2016/10/27.
 */

public class InsertProductInfoPresenter extends BasePresenter<BuildProductInfoFragment>
        implements InsertProductInfoContract.InsertProductInfoPesenter {


    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new InsertProductInfoModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {

        HashMap<String, IModel> hashMap = new HashMap<>();

        hashMap.put("insertProduct", models[0]);


        return hashMap;
    }


    @Override
    public void insertProductInfo(String code, String name, String type, String ccode, String length, String width, String height, String unit, String maxstock, String typename, String CoverPage, String contentpage, String minstock) {

        if (!getIView().checkNull()) {

            ((InsertProductInfoModel) getiModelMap().get("insertProduct"))
                    .insertProductInfo(code, name, type, ccode, length, width, height, unit,
                            maxstock, typename, CoverPage, contentpage, minstock
                            , new InsertProductInfoModel.InsertProductOnLinstener() {
                                @Override
                                public void insertPISuccess(InsertStatus insertStatus) {


                                    getIView().insertPIData(insertStatus);


                                }

                                @Override
                                public void insertPIFail(Throwable throwable) {

                                    getIView().hidePIData(throwable);
                                }
                            });

        }
    }
}
